package gov.dhs.cis.soa.data;

import gov.dhs.cis.soa.Constants;
import gov.dhs.cis.soa.Utils;
import gov.dhs.cis.soa.Constants.EntityType;

import java.util.ArrayList;
import java.util.List;


public class RuleSet extends AbstractSOAData {
	public static final String STEREO_TYPE = "RuleSet";
	
	public int id;
	public int rSetId;
	public String name;
	public String stereoType;
	public String maturity = "3";
	public String IST;
	public String domain;
	public String release = "A";
	public String descText;

	public Description desc;
	
	public List<Rule> rulesList = null;
	
	@Override
	public String toString() {
		String ret = "RuleSet [id=" + id + ", name=" + name + ", Desc = " + desc + "] ";
		return ret;
	}
	
	public void createDescription() {
		StringBuffer txt = new StringBuffer();
		if(Utils.isEmpty(descText))
			descText = "";
		txt.append(Constants.NL+descText);

		desc = Utils.prepareDescObj(txt.toString(), EntityType.RSET);
	}

//	public static String getUMLId(int entityId) {
//		return EntityType.APPL + "_" + entityId;
//	}

	public void add(Rule sOp) {
		if(rulesList == null)
			rulesList = new ArrayList<Rule>();
		rulesList.add(sOp);
	}
	
	public Rule findRule(String opName) {
		if(rulesList == null || Utils.isEmpty(opName))
			return null;
		opName = opName.trim();
		for (Rule o : rulesList) {
			if (o.name.trim().equalsIgnoreCase(opName))
				return o;
		}
		return null;
	}
	
	@Override
	public long getId() {
		return id;
	}
	@Override
	public String getHashableId() {
		return name;
	}

	@Override
	public EntityType getUMLType() {
		return EntityType.RSET;
	}
}

